<?php
// Copyright 2022 Hackware SpA <human@hackware.cl>
// This file is part of "Hackware Web Services Payment" and licensed under
// the terms of the GNU Affero General Public License version 3, or (at your
// option) a later version. You should have received a copy of this license
// along with the software. If not, see <https://www.gnu.org/licenses/>.

namespace Hawese\Payment\Gateways;

use Hawese\Payment\Support\Http as HttpSupport;
use UnexpectedValueException;

class DLocalGoRequestBuilder extends AbstractRequestBuilder
{
    const ENDPOINT = 'https://api.dlocalgo.com';
    const TEST_ENDPOINT = 'https://api-sbx.dlocalgo.com';

    private $credentials;

    public function __construct(...$args)
    {
        parent::__construct(...$args);
        $this->credentials = (object) config('gateways.dlocalgo.credentials');
        $this->addDefaultHeaders();
    }

    protected function getEndpoint(): string
    {
        if (config('gateways.dlocalgo.test_mode')) {
            return self::TEST_ENDPOINT;
        }
        return self::ENDPOINT;
    }

    private function addDefaultHeaders(): void
    {
        $this->headers['Content-Type'] = 'application/json';
        $this->headers['Authorization'] = 'Bearer ' .
            "{$this->credentials->apiKey}:{$this->credentials->secretKey}";
    }
}
